<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
    <meta name="author" content="火星科技 http://mars3d.cn " />
    <meta name="apple-touch-fullscreen" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="x5-fullscreen" content="true" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <!-- 标题及搜索关键字 -->
    <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
    <meta
      name="description"
      content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
    />

    <link rel="shortcut icon" type="image/x-icon" href="http://mars3d.cn/favicon.ico" />
    <title>Property属性机制演示 | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>

    <!--第三方lib-->
    <script
      type="text/javascript"
      src="../lib/include-lib.js"
      libpath="../lib/"
      include="jquery,font-awesome,bootstrap,layer,haoutil,turf,mars3d"
    ></script>

    <link href="css/style.css" rel="stylesheet" />
    <style>
      .infoview {
        width: 250px;
        line-height: 40px;
      }
    </style>
  </head>

  <body class="dark">
    <!--加载前进行操作提示，优化用户体验-->
    <div id="mask" class="signmask" onclick="removeMask()"></div>

    <div id="mars3dContainer" class="mars3d-container"></div>

    <!-- 面板 -->
    <div class="infoview">
      <div>属性机制演示：</div>
      <input type="button" class="btn btn-primary" value="SampleProperty" onclick="demoSampleProperty()" />
      <input type="button" class="btn btn-primary" value="TimeIntervalCollectionProperty" onclick="demoTimeIntervalCollectionProperty()" />
      <input type="button" class="btn btn-primary" value="ConstantProperty" onclick="demoConstantProperty()" />
      <input type="button" class="btn btn-primary" value="CompositeProperty" onclick="demoCompositeProperty()" />
      <input type="button" class="btn btn-primary" value="SampledPositionProperty" onclick="demoSampledPositionProperty()" />
      <input type="button" class="btn btn-primary" value="ColorMaterialProperty" onclick="demoColorMaterialProperty()" />
      <input type="button" class="btn btn-primary" value="ColorMaterialProperty2" onclick="demoColorMaterialProperty2()" />
      <input type="button" class="btn btn-primary" value="CallbackProperty" onclick="demoCallbackProperty()" />
      <input type="button" class="btn btn-primary" value="ReferenceProperty" onclick="demoReferenceProperty()" />
      <input type="button" class="btn btn-primary" value="PropertyBag" onclick="demoPropertyBag()" />
      <input type="button" class="btn btn-primary" value="VelocityVectorProperty" onclick="demoVelocityVectorProperty()" />
    </div>

    <script src="./js/common.js"></script>
    <script type="text/javascript">
      "use script"; //开发环境建议开启严格模式

      var map;
      var graphicLayer;

      function initMap(options) {
        //合并属性参数，可覆盖config.json中的对应配置
        var mapOptions = mars3d.Util.merge(options, {
          scene: {
            center: { lat: 31.81506, lng: 117.23734, alt: 1768, heading: 322, pitch: -33 },
            fxaa: true,
          },
        });

        //创建三维地球场景
        map = new mars3d.Map("mars3dContainer", mapOptions);

        // 创建矢量图层
        graphicLayer = new mars3d.layer.GraphicLayer();
        map.addLayer(graphicLayer);
      }

      function demoSampleProperty() {
        graphicLayer.clear();

        // 创建盒子
        var marsBox = new mars3d.graphic.BoxEntity({
          position: [117.220164, 31.834887, 39.6],
          style: {
            dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
            color: "rgba(0,255,255,0.8)",
            outline: true,
          },
        });
        graphicLayer.addGraphic(marsBox);

        //指定固定时间 ，方便写演示代码。
        map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"));

        // 演示属性机制
        var property = new Cesium.SampledProperty(Cesium.Cartesian3);
        property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), new Cesium.Cartesian3(400.0, 300.0, 100.0));
        property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:20")), new Cesium.Cartesian3(400.0, 300.0, 900.0));
        //让盒子一直存在
        // property.addSample(Cesium.JulianDate.fromDate(new Date('2017-08-26 00:00:00')), new Cesium.Cartesian3(400.0, 300.0, 900.0))

        marsBox.setStyle({ dimensions: property });
      }

      function demoTimeIntervalCollectionProperty() {
        graphicLayer.clear();

        //指定固定时间 ，方便写演示代码。
        map.clock.currentTime = Cesium.JulianDate.fromIso8601("2017-08-25T00:00:00.00Z");

        // 创建盒子
        var marsBox = new mars3d.graphic.BoxEntity({
          position: [117.220164, 31.834887, 39.6],
          style: {
            dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
            color: "rgba(255,255,0,0.8)",
            outline: true,
          },
        });
        graphicLayer.addGraphic(marsBox);

        // 演示属性机制
        var property = new Cesium.TimeIntervalCollectionProperty();
        property.intervals.addInterval(
          Cesium.TimeInterval.fromIso8601({
            iso8601: "2017-08-25T00:00:00.00Z/2017-08-25T00:00:02.00Z",
            isStartIncluded: true,
            isStopIncluded: false,
            data: new Cesium.Cartesian3(400.0, 300.0, 200.0),
          })
        );
        property.intervals.addInterval(
          Cesium.TimeInterval.fromIso8601({
            iso8601: "2017-08-25T00:00:02.00Z/2017-08-25T00:00:04.00Z",
            isStartIncluded: true,
            isStopIncluded: false,
            data: new Cesium.Cartesian3(400.0, 300.0, 400.0),
          })
        );
        property.intervals.addInterval(
          Cesium.TimeInterval.fromIso8601({
            iso8601: "2017-08-25T00:00:04.00Z/2017-08-25T00:00:06.00Z",
            isStartIncluded: true,
            isStopIncluded: false,
            data: new Cesium.Cartesian3(400.0, 300.0, 500.0),
          })
        );
        property.intervals.addInterval(
          Cesium.TimeInterval.fromIso8601({
            iso8601: "2017-08-25T00:00:06.00Z/2017-08-25T00:00:08.00Z",
            isStartIncluded: true,
            isStopIncluded: true,
            data: new Cesium.Cartesian3(400.0, 300.0, 700.0),
          })
        );

        marsBox.setStyle({ dimensions: property });
      }

      function demoConstantProperty() {
        graphicLayer.clear();

        // 创建盒子
        var marsBox = new mars3d.graphic.BoxEntity({
          position: [117.220164, 31.834887, 39.6],
          style: {
            dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
            color: "rgba(0,255,0,0.8)",
            outline: true,
          },
        });
        graphicLayer.addGraphic(marsBox);

        setTimeout(() => {
          // 演示属性机制

          //会创建一个新的ConstantProperty
          // marsBox.entityGraphic.dimensions = new Cesium.Cartesian3(400.0, 300.0, 200.0)

          //会修改原有的ConstantProperty的值。
          marsBox.entityGraphic.dimensions.setValue(new Cesium.Cartesian3(400.0, 300.0, 700.0));
        }, 2000);
      }

      //
      function demoCompositeProperty() {
        graphicLayer.clear();

        //指定固定时间 ，方便写演示代码。
        map.clock.currentTime = Cesium.JulianDate.fromIso8601("2017-08-25T00:00:00.00Z");

        // 创建盒子
        var marsBox = new mars3d.graphic.BoxEntity({
          position: [117.220164, 31.834887, 39.6],
          style: {
            dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
            color: "rgba(0,255,255,0.8)",
            outline: true,
          },
        });
        graphicLayer.addGraphic(marsBox);

        // 演示属性机制

        // 1 sampledProperty
        var sampledProperty = new Cesium.SampledProperty(Cesium.Cartesian3);
        sampledProperty.addSample(Cesium.JulianDate.fromIso8601("2017-08-25T00:00:00.00Z"), new Cesium.Cartesian3(400.0, 300.0, 100.0));
        sampledProperty.addSample(Cesium.JulianDate.fromIso8601("2017-08-25T00:00:10.00Z"), new Cesium.Cartesian3(400.0, 300.0, 500.0));

        // 2 ticProperty
        var ticProperty = new Cesium.TimeIntervalCollectionProperty();
        ticProperty.intervals.addInterval(
          Cesium.TimeInterval.fromIso8601({
            iso8601: "2017-08-25T00:00:10.00Z/2017-08-25T00:00:12.00Z",
            isStartIncluded: true,
            isStopIncluded: false,
            data: new Cesium.Cartesian3(400.0, 300.0, 600.0),
          })
        );
        ticProperty.intervals.addInterval(
          Cesium.TimeInterval.fromIso8601({
            iso8601: "2017-08-25T00:00:12.00Z/2017-08-25T00:00:14.00Z",
            isStartIncluded: true,
            isStopIncluded: false,
            data: new Cesium.Cartesian3(400.0, 300.0, 700.0),
          })
        );
        ticProperty.intervals.addInterval(
          Cesium.TimeInterval.fromIso8601({
            iso8601: "2017-08-25T00:00:14.00Z/2017-08-25T00:00:16.00Z",
            isStartIncluded: true,
            isStopIncluded: false,
            data: new Cesium.Cartesian3(400.0, 300.0, 800.0),
          })
        );
        ticProperty.intervals.addInterval(
          Cesium.TimeInterval.fromIso8601({
            iso8601: "2017-08-25T00:00:16.00Z/2017-08-25T00:00:18.00Z",
            isStartIncluded: true,
            isStopIncluded: true,
            data: new Cesium.Cartesian3(400.0, 300.0, 900.0),
          })
        );

        // 3 compositeProperty
        var compositeProperty = new Cesium.CompositeProperty();
        compositeProperty.intervals.addInterval(
          Cesium.TimeInterval.fromIso8601({
            iso8601: "2017-08-25T00:00:00.00Z/2017-08-25T00:00:10.00Z",
            data: sampledProperty,
          })
        );
        compositeProperty.intervals.addInterval(
          Cesium.TimeInterval.fromIso8601({
            iso8601: "2017-08-25T00:00:10.00Z/2017-08-25T00:00:20.00Z",
            isStartIncluded: false,
            isStopIncluded: false,
            data: ticProperty,
          })
        );

        // 4 设置dimensions
        marsBox.setStyle({ dimensions: compositeProperty });
      }

      // 使盒子进行移动
      function demoSampledPositionProperty() {
        graphicLayer.clear();

        // 创建盒子
        var marsBox = new mars3d.graphic.BoxEntity({
          position: [117.198461, 31.834956, 40.2],
          style: {
            dimensions: new Cesium.Cartesian3(100.0, 200.0, 300.0),
            color: "rgba(2,255,123,0.8)",
            outline: true,
          },
        });
        graphicLayer.addGraphic(marsBox);

        //指定固定时间 ，方便写演示代码。
        map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"));

        // 演示属性机制
        var property = new Cesium.SampledPositionProperty();
        property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), Cesium.Cartesian3.fromDegrees(117.198461, 31.834956, 40.2));
        property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:20")), Cesium.Cartesian3.fromDegrees(117.231979, 31.833411, 35.6));

        marsBox.position = property;
      }

      //
      function demoColorMaterialProperty() {
        graphicLayer.clear();

        // 创建盒子
        var marsBox = new mars3d.graphic.BoxEntity({
          position: [117.220164, 31.834887, 39.6],
          style: {
            dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
            color: "rgba(0,0,255,0.8)",
            outline: true,
          },
        });
        graphicLayer.addGraphic(marsBox);

        // 演示属性机制
        setTimeout(() => {
          marsBox.setStyle({ material: new Cesium.ColorMaterialProperty(new Cesium.Color(0, 1, 0)) });
          // 以上代码等同于
          // marsBox.setStyle({ material: new Cesium.Color(0, 1, 0) })
        }, 3000);
      }

      function demoColorMaterialProperty2() {
        graphicLayer.clear();

        // 创建盒子
        var marsBox = new mars3d.graphic.BoxEntity({
          position: [117.220164, 31.834887, 39.6],
          style: {
            dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
            color: "rgba(0,0,255,0.8)",
            outline: true,
          },
        });
        graphicLayer.addGraphic(marsBox);

        //指定固定时间 ，方便写演示代码。
        map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"));

        // 演示属性机制
        var colorProperty = new Cesium.SampledProperty(Cesium.Color);
        colorProperty.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), new Cesium.Color(0, 0, 1));
        colorProperty.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:10")), new Cesium.Color(1, 1, 0));

        marsBox.setStyle({ material: new Cesium.ColorMaterialProperty(colorProperty) });
      }

      //
      function demoCallbackProperty() {
        graphicLayer.clear();

        // 创建盒子
        var marsBox = new mars3d.graphic.BoxEntity({
          position: [117.220164, 31.834887, 39.6],
          style: {
            dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
            color: "rgba(0,255,255,0.8)",
            outline: true,
          },
        });
        graphicLayer.addGraphic(marsBox);

        // 演示属性机制
        var len = 100.0;
        var property = new Cesium.CallbackProperty(function (time, result) {
          result = result || new Cesium.Cartesian3(400.0, 300.0, 500.0);

          len += 3.0;
          if (len > 900.0) {
            len = 100.0;
          }

          result.x = 400.0;
          result.y = 300.0;
          result.z = len;

          return result;
        }, false);

        marsBox.setStyle({ dimensions: property });
      }

      //
      function demoReferenceProperty() {
        graphicLayer.clear();

        // 创建蓝色盒子
        var marsBox = new mars3d.graphic.BoxEntity({
          position: [117.220164, 31.834887, 39.6],
          style: {
            dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
            color: "rgba(0,0,255,0.8)",
            outline: true,
          },
        });
        graphicLayer.addGraphic(marsBox);

        //指定固定时间 ，方便写演示代码。
        map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"));

        // 演示属性机制
        var property = new Cesium.SampledProperty(Cesium.Cartesian3);
        property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), new Cesium.Cartesian3(400.0, 300.0, 100.0));
        property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:20")), new Cesium.Cartesian3(400.0, 300.0, 900.0));
        property.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-26 00:00:00")), new Cesium.Cartesian3(400.0, 300.0, 900.0)); //让盒子一直存在
        marsBox.setStyle({ dimensions: property });

        //另外一个红色盒子
        var redBox = new mars3d.graphic.BoxEntity({
          position: [117.225643, 31.843242, 37.9],
          style: {
            dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
            color: "rgba(255,0,0,0.8)",
            outline: true,
          },
        });
        graphicLayer.addGraphic(redBox);

        // 演示属性机制
        var collection = graphicLayer.dataSource.entities;
        let dimensions = new Cesium.ReferenceProperty(collection, marsBox.uuid, ["box", "dimensions"]);
        redBox.setStyle({ dimensions: dimensions });
      }

      //
      function demoPropertyBag() {
        graphicLayer.clear();

        // 创建盒子
        var marsBox = new mars3d.graphic.BoxEntity({
          position: [117.220164, 31.834887, 39.6],
          style: {
            dimensions: new Cesium.Cartesian3(400.0, 300.0, 500.0),
            color: "rgba(0,0,255,0.8)",
            outline: true,
          },
        });
        graphicLayer.addGraphic(marsBox);

        //指定固定时间 ，方便写演示代码。
        map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00"));

        // 演示属性机制
        var zp = new Cesium.SampledProperty(Number);
        zp.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:00")), 100.0);
        zp.addSample(Cesium.JulianDate.fromDate(new Date("2017-08-25 08:00:10")), 800.0);

        let dimensions = new Cesium.PropertyBag({
          x: 400.0,
          y: 300.0,
          z: zp,
        });
        marsBox.setStyle({ dimensions: dimensions });
      }

      //
      function demoVelocityVectorProperty() {
        graphicLayer.clear();

        let propertyFJ = getSampledPositionProperty([
          [117.198461, 31.834956, 40.2],
          [117.231979, 31.833411, 35.6],
        ]);
        var graphic = new mars3d.graphic.BillboardEntity({
          position: propertyFJ,
          orientation: new Cesium.VelocityOrientationProperty(propertyFJ),
          style: {
            image: "img/marker/huojian.svg",
            scale: 0.5,
            alignedAxis: new Cesium.VelocityVectorProperty(propertyFJ, true),
          },
        });
        graphicLayer.addGraphic(graphic);
      }

      //计算演示的SampledPositionProperty轨迹
      function getSampledPositionProperty(points) {
        let property = new Cesium.SampledPositionProperty();

        let start = map.clock.currentTime;
        let positions = mars3d.LatLngArray.toCartesians(points);
        for (let i = 0; i < positions.length; i++) {
          let time = Cesium.JulianDate.addSeconds(start, i * 20, new Cesium.JulianDate());
          let position = positions[i];
          property.addSample(time, position);
        }
        return property;
      }
    </script>
  </body>
</html>
